package com.cj.display_sys

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cj.display_sys.http.*

class MainViewModel : BaseViewModel() {

    private val repository by lazy {
        MainRepository()
    }

    private val parkEntity by lazy {
        MutableLiveData<ParkEntity>()
    }

    private val rows by lazy {
        MutableLiveData<Rows>()
    }

    private val weather by lazy { MutableLiveData<Weather>() }

    private val notice by lazy { MutableLiveData<Notice>() }

    fun getParkInfo(): LiveData<ParkEntity> {

        launchUI {
            val result = repository.getPark()
            parkEntity.value = result.data
        }

        return parkEntity
    }

    fun getWaterInfo(): LiveData<ParkEntity> {

        launchUI {
            val result = repository.getWater()
            parkEntity.value = result.data
        }

        return parkEntity
    }

    fun getNews(): LiveData<Rows> {
        launchUI {
            val result = repository.getNews()
            rows.value = result.rows
        }
        return rows
    }

    fun getWeather(city: String): LiveData<Weather> {
        launchUI {
            val result = repository.getWeather(city)
            weather.value = result.data
        }
        return weather
    }

    fun getNotice(): LiveData<Notice> {
        launchUI {
            val result = repository.getNotice()
            notice.value = result.data
        }
        return notice
    }
}